﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WeChatParking.Util
{
    public class Session
    {
        private static System.Web.SessionState.HttpSessionState _session
        {
            get
            {
                return System.Web.HttpContext.Current.Session;
            }
        }

        public static void SetSession(string key, object val)
        {
            _session[key] = val;
        }

        public static object GetSession(string key)
        {
            return _session[key];
        }

        public static string GetSessionStr(string key)
        {
            object val = GetSession(key);
            if (val == null)
                return string.Empty;
            return val.ToString();
        }

        public static T GetSession<T>(string key)
        {
            object val = GetSession(key);
            if (val == null)
                return default(T);
            return (T)val;
        }

        public static void RemoveSession(string key)
        {
            _session.Remove(key);
        }

        public static void RemoveAll(bool abandon = true)
        {
            _session.RemoveAll();
            if (abandon)
                _session.Abandon();
        }
    }
}
